<?
class Email
{
	private $from, $message, $headers;
	/**
	 * Construct email class object
	 *
	 * @param string $from
	 * @param string $message
	 * @param string $contenttype
	 * @param string $charset
	 * TODO: Very weak class. Need update. The bat! headers using, because russian anti-spam engine (yandex.spamoborona) kill all other.
	 */
	public function __construct($from, $message, $contenttype = 'plain', $charset = null)
	{
		if($charset === null) $charset = Sslib::Variable('page.charset');
		$this->from = $from;
		$this->message = $message;
		
		$this->headers = 
				'From: '.$this->from."\r\n".
				'Date: '.date('r')."\r\n".
				'MIME-Version: 1.0'."\r\n".
				'Content-transfer-encoding: 8bit'."\r\n".
				'Content-type: text/'.$contenttype.'; charset='.$charset."\r\n".
				'X-Mailer: The Bat! (v3.62.03) Professional'."\r\n".
				'Reply-To: '.$this->from."\r\n".
				"X-Priority: 3 (Normal)"."\r\n"
				;
		switch(strtoupper(substr(PHP_OS, 0, 3)))
		{
			
			case 'MAC':
				$this->headers = str_replace("\r\n", "\r", $this->headers);
				break;
			default: //'WIN':
				$this->headers = str_replace("\r\n", "\n", $this->headers);
				break;
		}
	}
	public function Send($to, $subject)
	{
		$to = trim(preg_replace('#[\n\r]+#s', '', $to));
		$subject = trim(preg_replace('#[\n\r]+#s', '', $subject));
		return mail($to, $subject, $this->message, $this->headers);
	}
}	
?>